package com.yjhh.scala

/**
  * 继承
  */
class PersonTemp {
  val counter = 3

  def counterArray = new Array(counter)
}

//val counter:Int 属性未被初始化，所以PersonTemp2类必须声明为抽象（abstract）的
abstract class PersonTemp2 {
  val counter: Int

  def counterArray = new Array(counter)
}

class Sporter extends PersonTemp2 {
  override val counter = 5
}

//Sporter 与 Sporter2是等同的效果
class Sporter2 extends {
  override val counter = 5
} with PersonTemp

//重写equals 和 hashCode
class Programmer(val name: String, val salary: Double) {
  final override def equals(obj: scala.Any): Boolean = {
    val that = obj.asInstanceOf[Programmer]
    if (that == null) false
    else name == that.name && salary == that.salary
  }

  final override def hashCode(): Int = {
    name.hashCode * 17 + salary.hashCode() * 9
  }

}

object HelloOverrideField extends App {
  private val person = new Sporter
  println(person.counterArray.length)

  List(1,2,3) map {case i:Int=>i+1}

  val x= <persons>
    <person name="摇摆少年梦" age="27" />
    <person name="张三三"><name>张三</name><age>29</age></person>
    <person><name>李四</name><age name="30岁">30</age></person>
  </persons>
}
